/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boole.application.vue;

import boole.circuit.*;
import java.awt.FlowLayout;
import java.util.HashSet;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class VueCircuitFerme extends javax.swing.JFrame {
    
    private HashSet<VueComposant> generateurs = new HashSet();
    private HashSet<VueComposant> recepteurs = new HashSet();

    /**
     * Creates new form VueCircuitFerme
     */
    public VueCircuitFerme(CircuitFerme cf) {
        initComponents();
        addComposantsCircuit(cf);
        this.generateurPanel.setLayout(new FlowLayout());
        this.recepteurPanel.setLayout(new FlowLayout());
        pack();
    }
    
    private void addComposantsCircuit(Circuit cf) {
        for (_Composant c : cf.getOperateurs().values()) {
            if (c instanceof Recepteur) {
                addRecepteur((Recepteur) c);
            } else if (c instanceof Generateur) {
                addGenerateur((Generateur) c);
            } else if (c instanceof CircuitOuvert) {
                addComposantsCircuit((CircuitOuvert) c);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        generateurPanel = new javax.swing.JPanel();
        recepteurPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        generateurPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout generateurPanelLayout = new javax.swing.GroupLayout(generateurPanel);
        generateurPanel.setLayout(generateurPanelLayout);
        generateurPanelLayout.setHorizontalGroup(
            generateurPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        generateurPanelLayout.setVerticalGroup(
            generateurPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 126, Short.MAX_VALUE)
        );

        recepteurPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout recepteurPanelLayout = new javax.swing.GroupLayout(recepteurPanel);
        recepteurPanel.setLayout(recepteurPanelLayout);
        recepteurPanelLayout.setHorizontalGroup(
            recepteurPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 706, Short.MAX_VALUE)
        );
        recepteurPanelLayout.setVerticalGroup(
            recepteurPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 130, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(recepteurPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(generateurPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(generateurPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(recepteurPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel generateurPanel;
    private javax.swing.JPanel recepteurPanel;
    // End of variables declaration//GEN-END:variables

    private void addRecepteur(Recepteur recepteur) {
        VueComposant vr = recepteur.getView();
        recepteur.addObserver(vr);
        this.recepteurs.add(vr);
        this.recepteurPanel.add(vr);
    }
    
    private void addGenerateur(Generateur generateur) {
        VueComposant vg = generateur.getView();
        generateur.addObserver(vg);
        this.generateurs.add(vg);
        this.generateurPanel.add(vg);
    }
}
